{extend name="index/nav" /}}
{block name="main"}
<div class="body">
    <div class="">
        <h2>资讯管理</h2>
    </div>
    <div class="index-table">
        <table class="am-table am-table-bordered am-table-radius am-table-striped" id="mytable">
            <thead>
            <tr>
                <th>ID</th>
                <th>标题</th>
                <th>简介</th>
                <th>内容</th>
                <th>资讯等级</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</div>


<script src='/static/index/js/jquery-1.11.0.min.js'></script>
<script>
    $(function() {
        $('#collapse-nav2').addClass('am-in');
        //       屏幕高度
        var heigth = document.body.offsetHeight - 90;
        $('.body').css('height', heigth + 'px');

//      表格数据
        $.post("{:url('admin/index/tonewsAdmin')}", function (res) {
            res=JSON.parse(res);
            console.log(res);
            var result = [], hash = {};
            for (var i = 0; i<res.length; i++) {
                var elem = res[i].news_id;
                if (!hash[elem]) {
                    result.push(res[i]);
                    hash[elem] = true;
                }
            }
            res=result;
        })
    })

// id 传值
    $('#mytable').delegate('.imageAdmin','click',function(){
        var id=$(this).attr('data_id');
        document.cookie=id;
        var arr=document.cookie.split(';');
        var id=arr[arr.length-1];
        console.log(id);
        window.location.href='{:url("admin/index/newsImage")}';
    })

    //  删除
    $('#mytable').delegate('.image_delect','click',function(){
        var id=$(this).attr('data_id');
        $.post('{:url("admin/index/delNew")}',{id:id},function (res) {
            window.location.reload();
        })
    })

    //  编辑
    $('#mytable').delegate('.image_add','click',function(){
        var id=$(this).attr('data_id');
        document.cookie= id;
        var arr=document.cookie.split(';');
        var id=arr[arr.length-1];
         window.location.href='{:url("admin/index/goNewsEdit")}';
    })
</script>
{/block}